package myzd.client;

import libedge.domain.request.ResultWrapper;
import myzd.api.domain.ListResult;
import myzd.api.domain.PagedResult;
import myzd.client.domain.*;
import myzd.domain.DoctorAccount;
import myzd.domain.OrderPayment;
import myzd.domain.TrackDTO;
import myzd.domain.UserMenu;
import myzd.domain.enums.AppointmentStatus;
import myzd.domain.enums.OrderByType;
import myzd.domain.enums.OrderServiceType;
import myzd.domain.enums.OrderStatusType;
import myzd.domain.request.*;
import myzd.domain.response.Order;
import myzd.domain.response.PayPayment;
import myzd.domain.response.PaymentList;
import myzd.domain.response.RefundPayment;
import retrofit2.Call;
import retrofit2.http.*;

/**
 * @author zks
 * @since 2017/10/23 17:48
 */
public interface GenericTradingServiceClient {

  /**
   * 创建工单
   *
   * @param createAppointmentRequest 创建工单参数
   * @return 工单信息
   */
  @POST("api/v1/orders/appointments")
  Call<ResultWrapper<ServiceOrder>> createOrder(@Body CreateAppointmentRequest createAppointmentRequest, @Header("Authorization") String token);

  /**
   * 根据工单ID获取工单
   *
   * @param id    工单Id
   * @param token token
   * @return 工单详情
   */
  @GET("api/v1/orders/{id}")
  Call<ResultWrapper<ServiceOrder>> getOrderById(@Path("id") Long id, @Header("Authorization") String token);

  /**
   * 获取工单支付信息列表
   *
   * @param orderNumber 预约单号
   * @param token       token
   * @return 支付信息列表
   */
  @GET("api/v1/payments/{orderNumber}/list")
  Call<ResultWrapper<PaymentList>> getOrderPaymentByOrderNumber(@Path("orderNumber") Long orderNumber, @Header("Authorization") String token);

  /**
   * 获取工单记录列表
   *
   * @param id    工单ID
   * @param token token
   * @return 记录列表
   */
  @GET("api/v1/orders/{id}/orderTracks")
  Call<ResultWrapper<ListResult<TrackDTO>>> listTracks(@Path("id") Long id, @Header("Authorization") String token);

  /**
   * 添加收款账户
   *
   * @param token
   * @param orderNumber
   * @param doctorAccount
   * @return
   */
  @PUT("api/v1/orders/appointments/{orderNumber}/paymentAccount")
  Call<ResultWrapper<ServiceOrder>> addPayAccount(
    @Header("Authorization") String token,
    @Path("orderNumber") Long orderNumber,
    @Body DoctorAccount doctorAccount);

  /**
   * 编辑医学建议
   *
   * @param token
   * @param orderNumber
   * @param doctorListRequest
   * @return
   */
  @POST("api/v1/orders/appointments/{orderNumber}/recommendDoctors")
  Call<ResultWrapper<ListResult<DoctorRequest>>> recommendDoctors(
    @Header("Authorization") String token,
    @Path("orderNumber") Long orderNumber,
    @Body ListRequest<DoctorRequest> doctorListRequest
  );

  @PUT("api/v1/orders/appointments/{orderNumber}")
  Call<ResultWrapper<ServiceOrder>> updateOrder(
    @Path("orderNumber") Long orderNumber,
    @Body ModifiedAppointmentRequest modifiedAppointmentRequest,
    @Header("Authorization") String token
  );

  @PUT("api/v1/orders/{id}/assignee")
  Call<ResultWrapper<ServiceOrder>> reassign(
    @Path("id") Long id,
    @Body ChangeAssigneeRequest changeAssigneeRequest,
    @Header("Authorization") String token
  );

  @PUT("api/v1/orders/appointments/{orderNumber}/confirmedDoctor")
  Call<ResultWrapper<ServiceOrder>> confirmedDoctor(
    @Path("orderNumber") Long orderNumber,
    @Body ConfirmDoctorRequest confirmDoctorRequest,
    @Header("Authorization") String token
  );

  @PUT("api/v1/orders/appointments/{orderNumber}/completeOrder")
  Call<ResultWrapper<ServiceOrder>> completeOrder(
    @Path("orderNumber") Long orderNumber,
    @Body CompleteOrderRequest completeOrderRequest,
    @Header("Authorization") String token
  );

  @POST("api/v1/orders/{id}/reminders")
  Call<ResultWrapper<CreateReminderRequest>> createReminder(
    @Path("id") Long id,
    @Body CreateReminderRequest createReminderRequest,
    @Header("Authorization") String token
  );

  @POST("api/v1/orders/{id}/notes")
  Call<ResultWrapper<PostNotes>> createTrack(
    @Path("id") Long id,
    @Body PostNotes postNotes,
    @Header("Authorization") String token
  );

  @POST("api/v1/payments/{paymentNumber}/transfer")
  Call<ResultWrapper<PayPayment>> transfer(@Path("paymentNumber") Long paymentNumber, @Header("Authorization") String token);

  @POST("api/v1/payments/{paymentNumber}/refund")
  Call<ResultWrapper<RefundPayment>> refund(@Path("paymentNumber") Long paymentNumber, @Header("Authorization") String token);

  @GET("api/v1/payments/{paymentNumber}")
  Call<ResultWrapper<ServicePayment>> getByPaymentNumber(@Path("paymentNumber") Long paymentNumber, @Header("Authorization") String token);

  @GET("api/v1/menus/{staffId}")
  Call<ResultWrapper<ListResult<UserMenu>>> getUserMenu(
    @Path("staffId") String staffId,
    @Header("Authorization") String token
  );

  @POST("api/v1/menus/{staffId}")
  Call<ResultWrapper<ListResult<UserMenu>>> setUserMenu(
    @Path("staffId") String staffId,
    @Body ListRequest<UserMenu> userMenuListRequest,
    @Header("Authorization") String token
  );

  @PUT("api/v1/orders/appointments/{orderNumber}/cancelOrder")
  Call<ResultWrapper<ServiceOrder>> cancelOrder(
    @Path("orderNumber") Long orderNumber,
    @Body CancelOrderRequest cancelOrderRequest,
    @Header("Authorization") String token
  );

  @GET("api/v1/orders")
  Call<ResultWrapper<PagedResult<Order>>> searchOrder(
    @Query("exclude_appointment_status") AppointmentStatus[] excludeAppointmentStatus,
    @Query("exclude_assignee_id") String excludeAssigneeId,
    @Query("creatorId") String creatorId,
    @Query("isAssigned") Boolean isAssigned,
    @Query("assignee_id") String assigneeId,
    @Query("assigneeDepartment") Integer assigneeDepartment,
    @Query("previousAssigneeId") String previousAssigneeId,
    @Query("previousAssigneeName") String previousAssigneeName,
    @Query("previousAssigneeDepartment") Integer previousAssigneeDepartment,
    @Query("completeAssigneeId") String completeAssigneeId,
    @Query("id") Long id,
    @Query("orderNumber") Long orderNumber,
    @Query("patientName") String patientName,
    @Query("patientPhone") String patientPhone,
    @Query("createdAt") String orderCreatedAt,
    @Query("serviceType") OrderServiceType serviceType,
    @Query("orderByType") OrderByType orderByType,
    @Query("orderStatus") OrderStatusType orderStatus,
    @Query("appointmentStatus") AppointmentStatus appointmentStatus,
    @Query("hideTest") Boolean hideTest,
    @Query("page") Integer page,
    @Query("pageSize") Integer pageSize,
    @Header("Authorization") String token
  );

  @GET("api/v1/enums")
  Call<ResultWrapper<CommonEnums>> getEnumList();

  @POST("api/v1/payments")
  Call<ResultWrapper<OrderPayment>> createPayment(@Body CreatePaymentRequest createPaymentRequest, @Header("Authorization") String token);

  @GET("api/v1/payments/{orderNumber}/list")
  Call<ResultWrapper<PaymentList>> getPaymetListByOrderNumber(
    @Path("orderNumber") Long orderNumber,
    @Header("Authorization") String token
  );

  @GET("api/v1/payments/financeData")
  Call<ResultWrapper<FinanceDto>> getFinanceData(
    @Query("startTime") String startTime,
    @Query("endTime") String endTime,
    @Query("timeType") String exportPaymentType,
    @Header("Authorization") String token
  );
}
